A class for making DOM elements draggable (including touch support). Used internally for map and marker dragging. Only works for elements that were positioned with L.DomUtil.setPosition
.
用于使DOM元素可拖动(包括触摸支持)的类。内部用于地图和标记拖动。仅适用于使用L.DomUtil.setPosition定位的元素。
Usage example
var draggable = new L.Draggable(elementToDrag);
draggable.enable();
Constructor
Constructor | Description |
---|---|
L.Draggable(<HTMLElement> el, <HTMLElement> dragHandle?, <Boolean> preventOutline?, <Draggable options> options?) | Creates a Draggable object for moving el when you start dragging the dragHandle element (equals el itself by default).开始拖动dragHandle元素时,创建一个可拖动对象以移动el(默认情况下等于el本身)。 |
Options
Events
Event | Data | Description |
---|---|---|
down | Event | Fired when a drag is about to start. 拖动即将开始时激发。 |
dragstart | Event | Fired when a drag starts 拖动开始时激发 |
predrag | Event | Fired continuously during dragging before each corresponding update of the element’s position. 在每次相应更新元素位置之前,在拖动期间连续激发。 |
drag | Event | Fired continuously during dragging. 拖动过程中连续激发。 |
dragend | DragEndEvent | Fired when the drag ends. 拖动结束时激发。 |
Methods
Method | Returns | Description |
---|---|---|
enable() |
| Enables the dragging ability 启用拖动功能 |
disable() |
| Disables the dragging ability 禁用拖动功能 |
▶ Methods inherited from Evented
从Evented继承的方法
Method | Returns | Description |
---|---|---|
on(<String> type, <Function> fn, <Object> context?) | this | Adds a listener function (fn ) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick' ).向对象的特定事件类型添加侦听器函数(fn)。您可以选择指定侦听器的上下文(this关键字将指向的对象)。您还可以传递几个空格分隔的类型(例如“click dblclick”)。 |
on(<Object> eventMap) | this | Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} 添加一组类型/侦听器对,例如{click:onClick,mousemove:onMouseMove} |
off(<String> type, <Function> fn?, <Object> context?) | this | Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on , you must pass the same context to off in order to remove the listener.删除以前添加的侦听器函数。如果没有指定函数,它将从对象中删除该特定事件的所有侦听器。请注意,如果您将自定义上下文传递给on,则必须将相同的上下文传递给off才能删除侦听器。 |
off(<Object> eventMap) | this | Removes a set of type/listener pairs. 删除一组类型/侦听器对。 |
off() | this | Removes all listeners to all events on the object. This includes implicitly attached events. 删除对象上所有事件的所有侦听器。这包括隐式附加的事件。 |
fire(<String> type, <Object> data?, <Boolean> propagate?) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. 激发指定类型的事件。您可以选择提供一个数据对象-侦听器函数的第一个参数将包含其属性。可以选择将事件传播到事件父级。 |
listens(<String> type, <Boolean> propagate?) | Boolean | Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.如果特定事件类型附加了任何侦听器,则返回true。可以选择传播验证,如果父级附加了侦听器,验证将返回true。 |
once(…) | this | Behaves as on(…) , except the listener will only get fired once and then removed.表现为on(…),但监听器只会被解雇一次,然后被移除。 |
addEventParent(<Evented> obj) | this | Adds an event parent – an Evented that will receive propagated events添加事件父级-将接收传播事件的Evented |
removeEventParent(<Evented> obj) | this | Removes an event parent, so it will stop receiving propagated events 删除事件父级,因此它将停止接收传播的事件 |
addEventListener(…) | this | Alias to on(…) |
removeEventListener(…) | this | Alias to off(…) |
clearAllEventListeners(…) | this | Alias to off() |
addOneTimeEventListener(…) | this | Alias to once(…) |
fireEvent(…) | this | Alias to fire(…) |
hasEventListeners(…) | Boolean | Alias to listens(…) |